#pragma once

#include "otlkcon_prop2str.h"

class otlkcon_debug
{

public:
	otlkcon_debug(void);
	~otlkcon_debug(void);
	void Initialize(LPALLOCATEBUFFER lpAllocateBuffer, LPFREEBUFFER lpFreeBuffer);
	

	// obtains symbolic prop name if found
	void TracePropTag(ULONG ulTraceFlags, ULONG ulPropTag, wchar_t* lpszMessage);
	void TracePropTagArray(ULONG ulTraceFlags, LPSPropTagArray lpsptaProps, wchar_t* lpszMessage);
	void TracePropTagArray(ULONG ulTraceFlags, ULONG *lpPropTags, ULONG cValues, wchar_t* lpszMessage);
	void TracePropTagArray(ULONG ulTraceFlags, LPSPropValue lpProps, ULONG cValues, wchar_t* lpszMessage);

	void TracePropValue(ULONG ulTraceFlags, LPSPropValue lpPropValue, wchar_t* lpszMessage);
	void TracePropValueArray(ULONG ulTraceFlags, LPSPropValue lpPropValues, ULONG cValues, wchar_t* lpszMessage);

	void TraceSRow(ULONG ulTraceFlags, LPSRow lpRow, wchar_t* lpszMessage);
	void TraceSRowSet(ULONG ulTraceFlags, LPSRowSet lpRowSet, wchar_t* lpszMessage);

	BOOL GetTagName(ULONG ulPropTag, wchar_t* lpszBuffer, size_t cchBufferLenght);
	BOOL GetPropValue(LPSPropValue lpPropValue, wchar_t* lpszBuffer, size_t cchBufferLenght);
	bool CanTrace(unsigned long ulTraceFlags);

protected:
	otlkcon_prop2str	m_Prop2Str;
	LPALLOCATEBUFFER	m_lpAllocateBuffer;
	LPFREEBUFFER		m_lpFreeBuffer;
	bool				m_bInitialized;
};

extern otlkcon_debug debugObj;

#define cch(_array_) (sizeof(_array_)/sizeof((_array_)[0]))

void SystemTimeToSTR(SYSTEMTIME *pst, wchar_t* lpszBuffer, size_t cchBufferLenght);
void FileTimeToSTR(FILETIME *pft, wchar_t* lpszBuffer, size_t cchBufferLenght);
LPCWSTR GetErrorString(ULONG ulError);



#ifdef _PROPERTIES_TRACE_
//real trace stuff
#define TRACE_PROP_TAG(_flags_,_tag_,_message_)	debugObj.TracePropTag((_flags_),(_tag_),(_message_))

#define TRACE_PROP_TAGS(_flags_,_tag_array_,_tag_count_,_message_)	debugObj.TracePropTagArray((_flags_),(_tag_array_),(_tag_count_),(_message_))
#define TRACE_SPROPTAG_ARRAY(_flags_,_sproptag_array_,_message_)	debugObj.TracePropTagArray((_flags_),(_sproptag_array_),(_message_))
#define TRACE_PROPVALUE_TAGS(_flags_,_prop_values_,_prop_count_,_message_)	debugObj.TracePropTagArray((_flags_),(_prop_values_),(_prop_count_),(_message_))
#define TRACE_PROPVALUE(_flags_,_prop_value_,_message_)	debugObj.TracePropValue((_flags_),(_prop_value_),(_message_))
#define TRACE_PROPVALUES(_flags_,_prop_values_,_prop_count_,_message_)	debugObj.TracePropValueArray((_flags_),(_prop_values_),(_prop_count_),(_message_))
#define TRACE_ROW(_flags_,_row_,_message_)	debugObj.TraceSRow((_flags_),(_row_),(_message_))
#define TRACE_ROWSET(_flags_,_rowset_,_message_)	debugObj.TraceSRowSet((_flags_),(_rowset_),(_message_))
	
#else
//Just stubs
#define TRACE_PROP_TAG(_flags_,_tag_,_message_)

#define TRACE_PROP_TAGS(_flags_,_tag_array_,_tag_count_,_message_)
#define TRACE_SPROPTAG_ARRAY(_flags_,_sproptag_array_,_message_)
#define TRACE_PROPVALUE_TAGS(_flags_,_prop_values_,_prop_count_,_message_)
#define TRACE_PROPVALUE(_flags_,_prop_value_,_message_)
#define TRACE_PROPVALUES(_flags_,_prop_values_,_prop_count_,_message_)
#define TRACE_ROW(_flags_,_row_,_message_)
#define TRACE_ROWSET(_flags_,_rowset_,_message_)

#endif